home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PsL Monthly 1993 December
/
PSL Monthly Shareware CD-ROM (December 1993).iso
/
prgmming
/
dos
/
c
/
tagsgen.exe
/
ASMTAG.C
< prev
next >
Wrap
C/C++ Source or Header
|
1991-11-18
|
20KB
|
559 lines
/*
EPSHeader
File: asmtag.c
Author: J. Kercheval
Created: Sun, 07/14/1991 17:25:26
*/
/*
EPSRevision History
J. Kercheval Sun, 07/14/1991 20:25:59 creation
J. Kercheval Mon, 07/15/1991 22:47:30 finish finite state machine parser
J. Kercheval Wed, 07/17/1991 21:35:43 add IsMember() and get_token()
J. Kercheval Thu, 07/18/1991 19:57:34 add flags checking
J. Kercheval Sun, 07/21/1991 15:58:56 add comment block support
J. Kercheval Sat, 07/27/1991 21:16:53 remove public post process support
J. Kercheval Sat, 07/27/1991 22:50:49 performance considerations (+10%)
J. Kercheval Sat, 08/10/1991 17:48:28 speed up IsMember()
J. Kercheval Sat, 08/17/1991 22:50:29 use unique function names (ASM...)
J. Kercheval Sun, 08/25/1991 23:52:51 fix bug in ASMSymbolWanted()
J. Kercheval Thu, 10/03/1991 12:27:37 fix logic outputting local labels
*/
#include <stdlib.h>
#include <string.h>
#include "asmtag.h"
#include "tagio.h"
/*
* The finite state machine allows the following interesting paths
*
* 1 - Discard, Parse1, Symbol1
* 2 - Discard, Parse1, Parse2, Symbol2
* 3 - Discard, Parse1, Parse2, Define
*
* all the important cases follow one of these paths according to MASM/TASM
* syntax. The exit state is for finish up routine calls and some paths not
* covered here are simple error paths and probably result from syntax errors
*/
enum state {
Discard, Parse1, Parse2, Symbol1, Symbol2, Define, Exit
};
typedef enum state State;
#define COMMENT_CHAR ';'
#define SYMBOL_SIZE 15
/*----------------------------------------------------------------------------
*
* The symbol lists represent all the symbols we are interested in either
* obtaining or ignoring. The order of some of these token lists is
* important for determining if ouput should be performed. If you want to
* change these lists make sure that flag checking is altered to change the
* changed order. The first element of each of these symbol lists is a
* string containing all the first characters within the symbol list. This
* allows faster rejection for IsMember() which is called often.
*
---------------------------------------------------------------------------*/
/* symbols which are not significant for this parser */
char ASM_NOP_Sym[][SYMBOL_SIZE] =
{
"cpbfnwo", /* list of starting characters of symbols
* below */
"c", /* C language declaration */
"pascal", /* PASCAL language declaration */
"basic", /* BASIC language declaration */
"fortran", /* FORTRAN language declaration */
"prolog", /* PROLOG language declaration */
"nolanguage", /* generic language declaration */
"windows", /* WINDOWS exit and entry modifier */
"oddnear", /* overlay modifier */
"oddfar", /* overlay modifier */
"normal", /* normal procedure entry/exit code */
"\0"
};
/* symbols which begin a comment block */
char ASM_comment_block[][SYMBOL_SIZE] =
{
"c", /* list of starting characters of symbols
* below */
"comment", /* begin comment block, next character is
* delimiter */
"\0"
};
/* create the function for determining if a character is a delimiter */
#define IsDelim(c) ( _ASM_delim_table[c] )
/* the indexed table for white space character lookup */
BOOLEAN _ASM_delim_table[256];
/* valid delimiters for this syntax */
char ASM_delim[] = " \t;:=.,\"()<>[]*-+/";
/* create the function for determining if a character is a whitespace */
#define IsWhite(c) ( _ASM_white_table[c] )
/* the indexed table for white space character lookup */
BOOLEAN _ASM_white_table[256];
/* whitespace characters */
char ASM_white[] = " \t\v\f";
/* symbols which both are delimiters and a special token, these are
special tokens only when found at the the beginning of a string of
1 or more delimiters */
char ASM_delim_Sym[] = "=:";
/* symbols which fit into the Define state and represent a tagged symbol */
/* state Define depends on the token ":" being at index 1 in this list */
char ASM_def[][SYMBOL_SIZE] =
{
":e=cd", /* list of starting characters of symbols
* below */
":", /* local labels */
"equ", /* equivalence */
"=", /* equivalence */
"catstr", /* concatenated and named strings */
"db", /* named byte data definition */
"dw", /* named word data definition */
"dd", /* named double word data definition */
"dp", /* named 6 byte far pointer data area
* definition */
"df", /* named 6 byte far pointer definition */
"dq", /* named quad word data definition */
"dt", /* named 10 byte data area */
"\0"
};
/* symbols which fit into the Symbol state and represent a tagged symbol */
char ASM_sym[][SYMBOL_SIZE] =
{
"pmlsu", /* list of starting character of symbols
* below */
"proc", /* procedures */
"macro", /* macros */
"label", /* local labels */
"struc", /* structures */
"union", /* unions */
"\0"
};
/*----------------------------------------------------------------------------
*
* ASMParserInit() initializes the tables required by the parser The tables
* used are a simple boolean index which are true if the character
* corresponding to the index is a member of the associated table.
*
---------------------------------------------------------------------------*/
void ASMParserInit()
{
char *s;
int i;
/* init the entire block to FALSE */
for (i = 0; i < 256; i++) {
_ASM_delim_table[i] = FALSE;
_ASM_white_table[i] = FALSE;
}
/* set the characters in the delim set to TRUE */
for (s = ASM_delim; *s; s++) {
_ASM_delim_table[*s] = TRUE;
}
/* NULL is also a delimiter */
_ASM_delim_table['\0'] = TRUE;
/* set the characters in the white set to TRUE */
for (s = ASM_white; *s; s++) {
_ASM_white_table[*s] = TRUE;
}
}
/*----------------------------------------------------------------------------
*
* ASMSymbolWanted() returns true if the index into the sym token list is one
* of the wanted symbols according to the flags list. The indexes belong
* with the following symbols and flags:
*
* Flag Symbol Index
* --------- ------- -----
* flags->af "proc" 1
* flags->am "macro" 2
* flags->al "label" 3
* flags->as "struc" 4
* flags->au "union" 5
*
---------------------------------------------------------------------------*/
BOOLEAN ASMSymbolWanted(Flags * flags, int index)
{
/* return true if the associated flag is true */
switch (index) {
case 1:
return flags->af;
break;
case 2:
return flags->am;
break;
case 3:
return flags->al;
break;
case 4:
return flags->as;
break;
case 5:
return flags->au;
break;
default:
return FALSE;
break;
}
}
/*----------------------------------------------------------------------------
*
* ASMIsMember() takes the token passed and check for membership in the null